package hyj.qx.websocket.vo;

import hyj.qx.websocket.enums.ErrorCode;
import lombok.Data;


@Data
public class JsonResult<T> {
    private String code;
    private String msg;
    private Boolean success;
    private T data;

    public JsonResult() {

    }

    public static <T> JsonResult<T> success(T data) {
        JsonResult<T> resultVo = new JsonResult<>();
        resultVo.setCode("200");
        resultVo.setMsg("成功");
        resultVo.setSuccess(true);
        resultVo.setData(data);
        return resultVo;
    }
    public static <T> JsonResult<T> Failed(T data,ErrorCode errorCode){
        JsonResult<T> resultVo = new JsonResult<>();
        resultVo.setCode(errorCode.getCode());
        resultVo.setMsg(errorCode.getMessage());
        resultVo.setSuccess(false);
        resultVo.setData(data);
        return resultVo;
    }
}
